package com.linchong.web;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.linchong.service.UserService;

@WebServlet("/checkUsername")
public class CheckUsername extends HttpServlet {

	private static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          //1.获得验校验的用户名
		  String username = request.getParameter("username");
		  
		 //2.传递username到service
		  UserService service = new UserService();
		  boolean isExist = false;
		  try {
			 isExist = service.checkUsername(username);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//3.返回结果
		  response.getWriter().write("{\"isExist\":"+isExist+"}");
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
